package com.dognessnetwork.customer.domain;
import org.springframework.util.Assert;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;

@Entity
@Table(name="chat_room")
/**
 * = Chatroom
 TODO Auto-generated class documentation
 *
 */
public class ChatRoom {

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    @Version
    private Integer version;
    /**
     * TODO 坐席
     */
    @NotNull
    private	String	seat;
    
    /**
     * TODO 用户
     *
     */
    private String	petUser;
    
    /**
     * TODO 聊天室状态
     */
    @NotNull
    private	RoomStatus	status;
    
    /**
     * TODO 客服上线时间
     */
    private	Long	seatAt;
    
    /**
     * TODO 用户上线时间
     */
    private	Long	petUserAt;
    
    /**
     * TODO 平均分
     */
    private	float	avgrate;
    
    /**
     * TODO 对客服的评论
     */
    @OneToMany(cascade = { javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.PERSIST }, fetch = FetchType.LAZY, mappedBy = "chatRoom")
    private Set<Comment> comment = new HashSet<Comment>();
    
    

	/**
     * TODO Auto-generated method documentation
     * 
     * @return Long
     */
    public Long getId() {
        return this.id;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @param id
     */
    public void setId(Long id) {
        this.id = id;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @return Integer
     */
    public Integer getVersion() {
        return this.version;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @param version
     */
    public void setVersion(Integer version) {
        this.version = version;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @return String
     */
    public String getSeat() {
        return this.seat;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @param seat
     */
    public void setSeat(String seat) {
        this.seat = seat;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @return String
     */
    public String getPetUser() {
        return this.petUser;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @param petUser
     */
    public void setPetUser(String petUser) {
        this.petUser = petUser;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @return RoomStatus
     */
    public RoomStatus getStatus() {
        return this.status;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @param status
     */
    public void setStatus(RoomStatus status) {
        this.status = status;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @return Long
     */
    public Long getSeatAt() {
        return this.seatAt;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @param seatAt
     */
    public void setSeatAt(Long seatAt) {
        this.seatAt = seatAt;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @return Long
     */
    public Long getPetUserAt() {
        return this.petUserAt;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @param petUserAt
     */
    public void setPetUserAt(Long petUserAt) {
        this.petUserAt = petUserAt;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @return Float
     */
    public float getAvgrate() {
        return this.avgrate;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @param avgrate
     */
    public void setAvgrate(float avgrate) {
        this.avgrate = avgrate;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @return Set
     */
    public Set<Comment> getComment() {
        return this.comment;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @param comment
     */
    public void setComment(Set<Comment> comment) {
        this.comment = comment;
    }

	/**
     * TODO Auto-generated attribute documentation
     * 
     */
    public static final String ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE = "The given Iterable of items to add can't be null!";

	/**
     * TODO Auto-generated attribute documentation
     * 
     */
    public static final String ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE = "The given Iterable of items to add can't be null!";

	/**
     * TODO Auto-generated method documentation
     * 
     * @param commentToAdd
     */
    public void addToComment(Iterable<Comment> commentToAdd) {
        Assert.notNull(commentToAdd, ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE);
        for (Comment item : commentToAdd) {
            this.comment.add(item);
            item.setChatRoom(this);
        }
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @param commentToRemove
     */
    public void removeFromComment(Iterable<Comment> commentToRemove) {
        Assert.notNull(commentToRemove, ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE);
        for (Comment item : commentToRemove) {
            this.comment.remove(item);
            item.setChatRoom(null);
        }
    }

	/**
     * This `equals` implementation is specific for JPA entities and uses 
     * the entity identifier for it, following the article in 
     * https://vladmihalcea.com/2016/06/06/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
     * 
     * @param obj
     * @return Boolean
     */
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        // instanceof is false if the instance is null
        if (!(obj instanceof ChatRoom)) {
            return false;
        }
        return getId() != null && Objects.equals(getId(), ((ChatRoom) obj).getId());
    }

	/**
     * This `hashCode` implementation is specific for JPA entities and uses a fixed `int` value to be able 
     * to identify the entity in collections after a new id is assigned to the entity, following the article in 
     * https://vladmihalcea.com/2016/06/06/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
     * 
     * @return Integer
     */
    public int hashCode() {
        return 31;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @return String
     */
    public String toString() {
        return "ChatRoom {" + 
                "id='" + id + '\'' + 
                ", version='" + version + '\'' + 
                ", seat='" + seat + '\'' + 
                ", petUser='" + petUser + '\'' + 
                ", seatAt='" + seatAt + '\'' + 
                ", petUserAt='" + petUserAt + '\'' + 
                ", avgrate='" + avgrate + '\'' + 
                ", ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE='" + ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE + '\'' + 
                ", ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE='" + ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE + '\'' + "}" + super.toString();
    }
}
